package com.baidu.cleaner.checker;

import org.apache.commons.lang3.StringUtils;

public class StringChecker implements Checker {
	private boolean isNull = false;
	private int length = 0;

	public boolean getIsNull() {
		return isNull;
	}

	public void setIsNull(boolean isNull) {
		this.isNull = isNull;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	@Override
	public boolean verify(String value) throws Exception {
		if (!isNull && StringUtils.isBlank(value)) {
			throw new Exception("the value can not be empty");
		} else if (isNull && StringUtils.isBlank(value)) {
			return true;
		} else {
			if (value.getBytes("GBK").length > this.length) {
				throw new Exception("the length of value is out of range");
			}

			return true;
		}
	}
}
